﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;

namespace CommonTagTime.DataAccess
{
    class daoBannerSlideConfig
    {
        public daoBannerSlideConfig()
        {

        }

        public bool Delete(int Id)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busBannerSlideConfig.Id, SqlDbType.Int);
                para[0].Value = Id;
                result = clsSQL.SPExecute("BannerSlideConfig_Delete", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoBannerSlideConfig", "Delete(BannerSlideConfig objBannerSlideConfig)", ex.ToString());

            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool DeleteAll()
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[0];
            try
            {
                result = clsSQL.SPExecute("BannerSlideConfig_DeleteAll", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoBannerSlideConfig", "DeleteAll()", ex.ToString());

            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool Insert(string SlideEffect)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busBannerSlideConfig.SlideEffect, SqlDbType.VarChar);
                para[0].Value = SlideEffect;
                result = clsSQL.SPExecute("BannerSlideConfig_Insert", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoBannerSlideConfig", "Insert(BannerSlideConfig objBannerSlideConfig)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if(result >0)
                return true;
            return false;
        }

        public BannerSlideConfig Load(IDataReader de)
        {
            BannerSlideConfig item = new BannerSlideConfig();
            item.Id = clsConvert.DbToInt("Id", de);
            item.SlideEffect = clsConvert.DbToString("SlideEffect", de);
            return item;
        }
        public BannerSlideConfig GetById(int Id)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            BannerSlideConfig item = new BannerSlideConfig();
            try
            {
                para[0] = new SqlParameter(busBannerSlideConfig.Id, SqlDbType.Int);
                para[0].Value = Id;
                de = clsSQL.SPDataReader("BannerSlideConfig_GetById", para);
                while (de.Read())
                {
                    item = Load(de);                    
                }
                de.Close();
                de.Dispose();
            }
            catch (Exception ex)
            {
                item = null;
                clsFile.WriteLog("daoBannerSlideConfig", "GetById(int Id)", ex.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return item;
        }
        public BannerSlideConfigCollection GetAll()
        {
            clsSQL clsSQL = new clsSQL();
            SqlDataReader de;
            BannerSlideConfigCollection items = new BannerSlideConfigCollection();
            try
            {
                de = clsSQL.SPDataReader("BannerSlideConfig_GetAll");
                while (de.Read())
                {
                    BannerSlideConfig item = Load(de);
                    items.Add(item);
                }
                de.Close();
                de.Dispose();
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoBannerSlideConfig", "GetAll()", ex.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }
            return items;
        }
    }
}
